package com.panopset.centralen.grid;

import static java.lang.Math.abs;
import static java.lang.Math.min;

import java.awt.Point;
import java.awt.Rectangle;

/**
 * Shape factory.
 *
 * @author Karl Dinwiddie
 *
 */
public class ShapeFactory {

    /**
     * Create rectangle from points.  Order does not matter.
     * @param a Point a.
     * @param b Point b.
     * @return Rectangle.
     */
    public Rectangle createRectangleFromPoints(final Point a,
            final Point b) {
        Rectangle r = new Rectangle();
        setRectangleFromPoints(r, a, b);
        return r;
    }

    /**
     * Set rectangle from points.
     * @param r Rectangle to set dimensions of.
     * @param a Point a.
     * @param b Point b.
     */
    public void setRectangleFromPoints(Rectangle r, final Point a,
            final Point b) {
        r.x = min(a.x, b.x);
        r.y = min(a.y, b.y);
        r.width = abs(b.x - a.x);
        r.height = abs(b.y - a.y);
    }
}
